<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <link rel="stylesheet" type="text/css" href="/framework/JSCal2/src/css/jscal2.css" />
    <link rel="stylesheet" type="text/css" href="/framework/JSCal2/src/css/border-radius.css" />
    <link rel="stylesheet" type="text/css" href="/framework/JSCal2/src/css/steel/steel.css" />
    <script src="/framework/JSCal2/src/js/jscal2.js"></script>
    <script src="/framework/JSCal2/src/js/lang/cn.js"></script>
    <style>.flexigrid{margin:10px;}</style>
    <title><!--{if $operFlg == 2}-->积分兑换添加<!--{else}-->积分兑换编辑<!--{/if}--></title>
    <!--{include file='comm/comm_pic.tpl'}-->
</head>
<body>
<div style="width:100%;">

    <div class="items clearfix">

        <h2 style="" class="tal">
            <!--{if $operFlg == 2}-->积分兑换添加<!--{else}-->积分兑换编辑<!--{/if}-->
        </h2>

        <div class="items2">

            <div>
                <form id="sendForm" name="sendForm" onsubmit="return false;">

                    <table>
                        <tr>
                            <td width="150" class="tar">促销活动名称：</td>
                            <td class="td_input">
                                <input type="text" id="promotionName" name="promotionName" style="width:535px;" value="<!--{$pointsConvertInfo->promotionName}-->">
                                <input type="hidden" id="promotionID" name="promotionID" value="<!--{$pointsConvertInfo->promotionID}-->">
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td class="tar">促销时间：</td>
                            <td width="*" class="td_input">
                                <input id="startDate" name="startDate" type="text" maxlength="20"  style="width:120px;" value="<!--{$pointsConvertInfo->startDate}-->" >
                                ～
                                <input id="endDate" name="endDate" type="text" maxlength="20"   style="width:120px;" value="<!--{$pointsConvertInfo->endDate}-->" >
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td width="150" class="tar">优惠券：</td>
                            <td class="td_input">
                                <select name="couponID" id="couponID" style="width:165px;">
                                    <option value="">请选择</option>
                                    <!--{foreach from=$accountCoupon item=c_l}-->
                                    <option value="<!--{$c_l->couponID}-->" <!--{if $c_l->couponID == $pointsConvertInfo->couponID}--> selected <!--{/if}--> ><!--{$c_l->couponName}--></option>
                                    <!--{/foreach}-->
                                </select>
                                <!--{if $accountCoupon|@count neq 0 }-->
                                    <font color="red">*</font>
                                <!--{else}-->
                                    <font color="red">没有找到可用的优惠券信息</font>
                                <!--{/if}-->
                            </td>
                        </tr>
                        <tr>
                            <td width="150" class="tar">兑换积分：</td>
                            <td class="td_input">
                                <input type="text" id="points" name="points" style="width:100px;" value="<!--{$pointsConvertInfo->points}-->">
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td class="tar">使用状态：</td>
                            <td width="*" class="td_input">
                                <input type="radio" name="useFlg" value="1" <!--{if $operFlg == 2 || $pointsConvertInfo->useFlg == 1}-->checked="checked"<!--{/if}-->>启用
                                <input type="radio" name="useFlg" value="0" <!--{if $operFlg == 3 && $pointsConvertInfo->useFlg == 0}-->checked="checked"<!--{/if}-->>禁用
                            </td>
                        </tr>
                    </table>

            </form>
        </div>

    </div>
</div>

<div class="bottom_fixbox">
    <div class="rectbox tac">
        <input type="hidden" id ="dataCache" name="dataCache" value="">
        <input type="button" class="btn" onclick="promotionAdd.check();" value="<!--{if $operFlg == 2}-->积分兑换添加<!--{else}-->积分兑换编辑<!--{/if}-->" />&nbsp;&nbsp;&nbsp;
        <input type="button" class="btn" onclick="E.closeWindows();" value="关闭" />
    </div>
</div>

</div>

<script>

    var operFlg = '<!--{$operFlg}-->';

    var promotionAdd = {

        //检查数据
        check: function() {

            this.dt = E.getFormValues("sendForm") ;

            var error_msg = "";

            if (this.dt.promotionName == "")
                error_msg += "促销标题不能为空<br />";

            if( this.dt.startDate == '' ){
                error_msg += "请输入促销开始时间<br />";
            }else{
                if (!E.isDate(this.dt.startDate))
                    error_msg += "促销开始时间格式不正确<br />";
            }

            if( this.dt.endDate == '' ){
                error_msg += "请输入促销结束时间<br />";
            }else{
                if (!E.isDate(this.dt.endDate))
                    error_msg += "促销结束时间格式不正确<br />";
            }

            if(this.dt.startDate > this.dt.endDate)
                error_msg += "促销开始时间不能大于结束时间<br />";

            if( this.dt.couponID == '' )
                error_msg += "请选择优惠券<br />";

            if( this.dt.points == '' ){
                error_msg += "兑换积分不能为空<br />";
            }else{

                if( !E.isInt(this.dt.points) )
                    error_msg += "兑换积分必须为正整数<br />";

            }


            if (error_msg != "")
                E.alert(error_msg);
            else
                promotionAdd.add();
        },

        //保存积分兑换信息
        add: function() {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/promotion/pointsConvert.ajax?operFlg=2" ,
                dataType: "JSON",
                data: this.dt,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {

                        E.opener("promotion.load");

                        if( operFlg == 2 ){
                            E.alert(result_obj.message, 2 , "E.refresh");
                        }else{
                            E.alert(result_obj.message, 2 , "E.closeWindows");
                        }

                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        }

    };

</script>
<script>
    var cal = Calendar.setup({
        showTime     : 24,
        onSelect: function(cal) { cal.hide() }
    });

    cal.manageFields("startDate", "startDate", "%Y-%m-%d");
    cal.manageFields("endDate", "endDate", "%Y-%m-%d");
</script>
</body>
</html>